piece algorithms implemented