Fixed the myriad of bugs that came with the previous commit