I guess it would be better to create a function for line 407-411? Since they are used twice here.