Added tests. Some design changes