improving some functionality and preventing some exceptions