fixing some syntax errors
some refactoring