Code cleanup, small fixes