Testmode added, code improvements