error estimation java code refactor