Refactored script with resharper warnings