optimized to send less data across, also made the empty array generation do less
work
cleaned up comments and unecessary code
added informative comments