refactor. still needs work and no longer operates at the moment