Fix unit size metric and do some refactoring to improve performance and to clean up code