Optimise function, fix excessive calling to split() function

Also initialise values with 0 to avoid potential crash, it's not likely this will happen but it makes the logic a bit more sound and makes static code analysers happy.