Cleaned up code and made some small fixes.