resolved last bug and improved various code