Added code for pruning, and rewrote command handler