Added some control code and new tests