input/output needs to be fixed but algorithm is working