Volodya K.'s comments implemented and minor bugs fixed