optimize code slightly, corrected problem with current_upto not properly memoizing, added more tests