more fixes & introduced some unit tests