yareg's code refactored again. we still have code to refactor