Fix issue #2, issue #3 and issue #4