refactor, make private methods private, handle more errors