Simplified main, added new function