Reorganizitng code to prepare for restler usage