Fixing errors for compilation and refactoring