up/down logic added