Made a better implementation of open()