Added more logic to help close #3.