Optimized command handling

Sorry I changed a lot of things but I believe that they are all necessary. Reverse them if you like (but please don't delete and recreate)