I will look at this code as soon as i get gome but i have a feeling you are not debouncing your input.
http://esp8266basic.com
A BASIC interpreter for your ESP
Working now on Autodrop3d. A 3d printer with automatic part ejection system. https://autodrop3d.com