Cleanup.

Changed for loops into ranged for loops, added checks for nullptr.

Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
Merge pull request #64 from lgromanowski/master

Cleanup.