Clean up code.

Thanks to Lawrence Teo for code reviewing this.
Code cleanup.