Several fixes and improvements

Hey @diegocr,

Have pushed this to a branch here so we can both push to it. 

Related to #178