json_encode() is faster than serialize()

ref: http://stackoverflow.com/a/7723730/2566213
calculate only once in loops
Merge pull request #52 from rindeal/feature/speed-optimizations

Just some speed optimizations