Fix issues #5, #12, #13, #14