Refactor check dependencies code

Hello,

i refactored the check dependencies code and moved it to a function. Now it looks nice :)