Various code improvements