Fixed a few issues with the code