moved code to more distinct functions for better usage in tutorials