refactored. old func working