added types and fixed api