Fixed majority of issues from last pull request

Only the mail thing is not resolved yet.