More refactoring.

Mostly refactored if-statements for checking whether certain commands are allowed. Should be ready to fill in some missing features.