Debugged the mess a bit. It works more consistently now.