Simplefied the code by removing Managed