Added pins support and simplified code