Refactored code, adds responding to commands