Fixed a few issues in code