Working tick algorithm this time... promise... (could still need a lot optimisation through..