working now, still needs more testing