Fixed #10 and Fixed #12. Fully tested