working basics but ugly code, especially in main