finish refractoring the code to work properly

AAHGHGAHGHAGHGHGAH