Added tests and fix issues from last commit