Fixed issues #36 (enhancement) and #37 (bug)