logic working + tested