Cleaned up code. Still not perfect but better.