Several code improvements