Code cleanup and clarification