A bit of code refactoring, added time measurement