Fixed some input bugs and memory leaks thanks to a test by a friend.