Fixed up some possible bugs thanks to IntelliJ