Updated creation of Executor to be used when needed

Updated the executor so that it will be used when it is needed and
destructed after.