Hopefully fixed a few bugs