added console input and added test cases;
minimal code refactor. added comments;