Some code pieces for common problems