various code improvements after inspection