Added valid signal, fixed several bugs, passing 5/6 tests