Attempt to fix tiobe score for this file

Split up the biggest function into smaller ones