final version with all required functionalities working