Fixed some bugs.
Optimized the code a little.
Pew pew.