Added new features and a little bit optimised the code