tidied up __main__ a little (not finished though)