fixing variable binding and other minor changes

fixing variable binding and other minor changes like changing some code
style.