cleaned up more code and made if and for statements look consistent with the rest of the coding style