Reworked sim into a class, optimized code