WIP. refactoring. removing duplicate functions