Trimmed it down and added functionality