big refactoring and cs fixing and started adding tests