Added Q for quit functionality and removed redunant code