Added a few tweaks to fix bugs and errors