Refactors command handling

Uses JSON objects full of handler functions rather than switch blocks