initial code, non-working (two scripts merged together currently)