Cleaned up lots of code