Change arpaTop into a function to reduce redundant code