refactoring binny's fixes for #1 , and other few minor fixes