added form and submit, plus tests and optimization