further refactoring. mostly by creating curried functions