Fixed a typo and did minor cleanup

$e should have been $element;
removed unused firstTop variable;
renamed $e to $element