Some patches

Feel free to take none/some/all of this code