this needs to be rewritten