added lives feature and refactored code