speeds added restructing of function logic