Add comments and cleanup code