tabs to spaces, minor commenting and refractoring