Change name of method and make it more robust