Fixed a few bugs, renamed var names