Code style

Various code style and bug fixes, minor optimization as well as remove uses of deprecated stuff in the chrome API.