Isn't there an already existing method for that?
Is there some code to share with the workspace?