added delay function, delay_ms wouldn't work immediately