Fixes NPE but needs a cleaner implementation.