Cleaned code and reordered variables