Fixed the code and things seem to be running fine now.