completed version with bugs