working code with some features commented