Modified code to use better practices reccomended by Niall and Scott after code review.