many changes to restructure the code. hopefully it doesn't crash n burn.