tests and logic fix