prototype reorganization
fixed variable scope errors
some spacing cleaning