Major code improvements. Haven't touched logic yet.