Implemented rollback functionality. Also removed the temp. data writing
and did some refactoring