Adding unit tests and fixing issue found (fix #12)