syntax fixes and refactor