Version 2: Final with LIBSTAT & LIBSHAR logic