Refactored code. Fixes rSPT67632600cc19