added main and bug fixes