inital working version for review

@jarv @feanil 
nit: avoid single letter variable names