Refactoring some things and doing some preliminary coding for the W function
Fix merging issues from my own work