2nd commit. bug fixes, optimized code..

Little Bug fixes, optimized code, improved java coding standards