Formatted and cleaned large portion of code

Signed-off-by: Jacky Boen <aqiank@gmail.com>