Fixed issues #13 and fixed found bugs