Fixing syntax and removing repeative code