More refactoring; Small optimization
Unit tests for utils; Small refactoring