Cleaned up lossless(...). Better exception handling, decomposition.