Added new features and some refactoring