Code corrections and cleanup