Tests working again, cleaned up code