added some helpers
minor tweaks
major code refactoring