refractored/cleaned the code a bit. some style changes.