Fixed bugz. Added tests