refactored quite a bit, added test for raising invalid command error