Fixed various issues from code inspection