algorithm cleanup, need to fix indefinite whileloop