Cleaned code and renamed things. Added Debug Logging