fixed #7, #5 and #8, almost ready to submit