Reorginized code and applied google's Code Style Guidelines