fixed identifier bug and did some refactoring