working but some logic issues