Input validation implemented, also did some related bugfixing.