Miscellaneous code improvements