finished main - needs testing