some adjustments. removed unnecessary code. more comments