Improved code, added reset method