merged in my old patch, needs *SERIOUS* cleanup