Refactored variable parsing, fix many bugs, add variable docs