in reply to error at line 77

Unless you're just doing this as an exercise, there is a module that does this.