bugs fixing and minor improvments