Removing redundancy and fixing a couple of bugs.