cleanup code, fix delays