Code cleanup & Bug fixes