Fixed bugs & reduced code

Fixed some small bugs and reduced some code to make the size of the mod
smaller to save space.