Some optimizations

Replaced function calls to array_push with adding the elements directly. This has 2 important advantages.

1. Speed
2. The code looks better this way.