Cleaned up code, removed unused functions.