refactored using STM
reduced example for better understanding, next is proper handling of requests