refactored code to be more readable and implement isInComponent(pos_t,pos_l,component) function