rafactored to remove comments and simplify methods