Igor and Sunny fixed a bug where readlink fails. Igor also cleaned up the code.