Updated source code
- bug fixes and some changes