The same logic worked after restarting Windows. Just refactored the code a little bit.