tested code after minor fixes