minor corrections, still needs more testing and cleaned up