simplify and improve speed