Code cleanup, minor fixes