Refactored some functions to clean them up
Fixed syntax error