Cleaned up several code issues