refactored code, algorithms may not be working