Added tests and used async functions where convenient.