Initial version. Rewritten version soon to come...