adding tests and fixing some issues