Cleaned up code, removed most compiler warnings.