working on make code shorter and more robust