Fixed issues #5, #6, #7, #9, #11, #12, #13