needs to be cleaned up, but works