Refactored to work with .Net 4