efficiency impromvements and code organization