re-arranged to work