Some tweaks, removed unused variables and new function added. Currently
its very experiemental.