The previous code was just a bit odd and non-standard + variable (and probably unefficient). Decided to replace it with standard Java functions instead.