Added comments and cleaned broken functions