bugs fixed, better tests