expanded tests, fixed several bugs