Reduced mem footprint

cherry-picked commits from PR #298, this doesnt introduce anything drastical, just remove/reduce some unused variables and function. 
Ready for inclusion once Travis passed. Thx