More rigorous error checking; return null if no device available of given type; added pseudocode documentation.