Switched to some built in php functions where i could