added utility function based on adjacency
refactored code and added move functions based on new adjacency utility function