Refactor code

Fixes #19.
var inside for, am I missing something? :)