Fixed some more bugs. Manual testing has been done, branch appears ready to be merged.