Added new features. Code refactored