consolidate piece-related code