Code refactored and fixed.

Woo