Refactor, add a little error handling.