Fix some issues according to the comments by @lunaryorn